
import type { KnowledgePage, KnowledgeParams,PageParams,DoctorPage,PartialConsult, 
    FollowType,TopDep,Image,ConsultOrderPreData, ConsultOrderPreParmas,ConsultOrderListParams, ConsultOrderPage,
ConsultOrderItem ,ConsultOrderParams,payUrl} from '@/types/consult'
import { request } from '@/utils/request'

//获取知识库列表
export const getKnowledgePage = (params: KnowledgeParams) =>
    request<KnowledgePage>('/patient/home/knowledge', 'GET', params)

//获取医生列表
export const getDoctorPage = (params: PageParams) =>
    request<DoctorPage>('/home/page/doc', 'GET', params)

export const followOrUnfollow = (id: string, type: FollowType = 'doc') =>
    request('/like', 'POST', { id, type })
//获取极速问诊的全部科室
export const getAllDep = () => request<TopDep[]>('/dep/all')

//上传图片
export const uploadImage = (file: File) => {
    const fd = new FormData()
    fd.append('file', file)
    return request<Image>('/upload', 'POST', fd)
  }

  //获取预支付订单的信息
export const getConsultOrderPre = (params: ConsultOrderPreParmas)=>{
    return request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)
}
// 生成订单
export const createConsultOrder = (data: PartialConsult) =>
    request<{ id: string }>('/patient/consult/order', 'POST', data)

// 订单接口
export const getConsultOrderPayUrl = (data: ConsultOrderParams) =>
    request<payUrl>('/patient/consult/pay', 'POST', data)


export const getConsultOrderList = (params: ConsultOrderListParams) =>
    request<ConsultOrderPage>('/patient/consult/order/list', 'GET', params)

// 取消订单
export const cancelOrder = (id: string) => request(`/patient/order/cancel/${id}`, 'PUT')

// 删除订单
export const deleteOrder = (id: string) => request(`/patient/order/${id}`, 'DELETE')
// 查看处方
export const getPrescriptionPic = (id: string) =>
    request<{ url: string }>(`/patient/consult/prescription/${id}`)

//查看订单详情
export const getConsultOrderDetail = (orderId: string) =>
    request<ConsultOrderItem>(`/patient/consult/order/detail`, 'GET', { orderId })
//支付接口
export const orderPayAPI = (data:ConsultOrderParams) => request<payUrl>('/patient/consult/pay', 'POST',data )

// 评价问诊
export const evaluateConsultOrder = (data: {
    docId: string
    orderId: string
    score: number
    content: string
    anonymousFlag: 0 | 1
  }) => request<{ id: string }>('/patient/order/evaluate', 'POST', data)
  
